package org.ns.summer.classpath.classreader;

import org.ns.summer.classpath.classreader.basictype.U1;

import java.io.InputStream;

/**
 * 常量池
 */
public class ConstantPool {
    public int TAG_pool_count; // 数量
    public ConstantInfo[] cpInfo; // 池子

    public ConstantPool(int count) {
        TAG_pool_count = count;
        cpInfo = new ConstantInfo[TAG_pool_count];
    }
	// 解析常量池
    public void read(InputStream inputStream) {
        for (int i = 1; i < TAG_pool_count; i++) {
            short tag = U1.read(inputStream);
            ConstantInfo constantInfo = ConstantInfo.getConstantInfo(tag);
            constantInfo.read(inputStream); // 从流中读取数据
            cpInfo[i] = constantInfo;
            if (tag == ConstantInfo.TAG_Double || tag == ConstantInfo.TAG_Long) {
                i++;
            }
        }
    }

}
